Xbasic

Array Methods

Description

Methods available for objects dimmed as arrays.

Discussion

Xbasic arrays have methods that can be used to initialize, add, remove, modify, and search data in the array as well as get information about the array, such as the array's size or whether or not it is dynamic. The methods below are available for every Xbasic array explicitly created using the DIM statement or implicitly created using the [] operator.

For example:

dim arr[0] as p
i = arr.append() 'add a new element
arr[i].name = "Sarah"
arr[i].city = "Providence"
arr[i].state = "RI"
arr[i].mode = "Bike"

i = arr.append() 'add new element
arr[i].name = "Frank"
arr[i].city = "Boston"
arr[i].state = "MA"
arr[i].mode = "Bus"

i = arr.append() 'add new element
arr[i].name = "James"
arr[i].city = "Portland"
arr[i].state = "OR"
arr[i].mode = "Walk"

? arr.size() ' get size of array
= 3

? arr.get_fields() ' list the fields in the property array
= name
city
state
mode

' dump the data in the array into a formatted list
? arr.dump_properties("Name|City|State|Mode")
= Sarah|Providence|RI|Bike
Frank|Boston|MA|Bus
James|Portland|OR|Walk

arr.clear() ' clear all data from the array

? arr[1] ' list the properties for arr[1]
= <Has no sub-properties>

For more information about creating and using Xbasic arrays, see Xbasic Arrays.

Methods

age Method

Get array's changed counter.

append Method

Append one or more empty entries to the end of an array. Returns index of first appended entry.

append_arrays Method

Appends one or more arrays to an array.

append_arrays_filtered Method

Appends one or more filtered arrays to an array.

class Method

Returns the class of the array. Will always return "Array" for an array.

clear Method

Clear the array.

copy_from Method

Copies elements from one array and inserts them into another.

delete Method

delete entries from array.

dimension Method

Get the number of dimensions in an array, such as for a multidimensional array.

dump Method

Create a CR-LF delimited string of a single dimensional array's contents.

dump_csv Method

Returns the property array as formatted csv. Optionally define the fields to include and whether or not field names should be included in the csv output in the first line of data.

dump_json Method

Creates a JSON string from data in a property array.

dump_properties Method

Dump the properties array to a string of newline separated entries.

filter Method

Removes entries from a property array that match or do not match a filter expression.

find Method

Find a value in the array, return the index of the entry, or 0 if not found.

findi Method

Find a value in the array, using case insensitive search. return the index of the entry, or 0 if not found.

first_empty Method

Return the last unused entry in the array.

for_each Method

Converts a property array to a formatted list of CR-LF separated entries.

get_dynamic Method

Indicates whether the dynamic sizing property of an array is on or off.

get_fields Method

Gets a CR-LF delimited list of fields for a property array.

get_recycle Method

Returns whether or not the array recycling is enabled.

initialize Method

Initialize the array from a string of newline separated entries.

initialize_from_csv Method

Initialize a property array with from a passed in CSV string.

initialize_from_table Method

Initialize property array subfields from a table.

initialize_properties Method

Initialize property array subfields from a string of newline separated 'rows'.

insert Method

Insert entries into array, resizing the array if needed.

isnull Method

Returns whether or not the array is null (has no values).

itemtype Method

Gets the data type of the elements in an array.

last_appended Method

The value of the last appended index.

lower Method

Returns the lower bound of the array.

matching Method

Returns a CR-LF delimited list of indices of array elements that match a filter.

move Method

Move an array entry from one position to another.

property_order Method

Get a property array order list.

push Method

Adds a new item to the array.

reorder Method

Reorder array elements.

resize Method

Resize an array, keeping its components intact.

set_dynamic Method

Turn on/off the dynamic sizing property of an array.

set_recycle Method

Enables or disable array element recycling.

setnull Method

Sets data to NULL.

size Method

Return the extent of the array optional dimension for multidimensional arrays.

sort Method

Sort the array.

touch Method

Manually increment the array's changed counter.

typename Method

Returns the typename of the array. The typename for an array will always be "A" (Array).

upper Method

Returns the upper bound of the array.

See Also